package thread;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 交替打印a-z 1-26
 *
 * @author yujiafan
 * @version 1.0.0
 * @create 2022-12-07
 */
public class Threada1b2 {

    static final Object o = new Object();
    static final Object o1 = new Object();

    static Lock lock = new ReentrantLock();


    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized(o){
                    for (int i = 'a'; i <= 'z'; i++) {
                        System.out.println((char) i);
                        try {
                            o.wait();
                            o1.notify();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }

            }
        });

        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized(o1){
                    for (int i = 1; i <= 26; i++) {
                        System.out.println(i);
                        try {
                            o1.wait();
                            o.notify();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }

            }
        });
        t1.start();
        Thread.sleep(1000);
        t2.start();
    }
}
